package _02_链表;

public class _82_删除排序链表中的重复元素II {

    public ListNode deleteDuplicates(ListNode head) {
        return deleteDuplicates(head, null);
    }

    public ListNode deleteDuplicates(ListNode head, ListNode prev) {
        if (head == null) return head;
        if (prev != null && prev.val == head.val) {
            return deleteDuplicates(head.next, head);
        } else if (head.next != null && head.val == head.next.val) {
            return deleteDuplicates(head.next.next, head.next);
        }  else {
            head.next = deleteDuplicates(head.next, head);
        }
        return head;
    }

}
